package com.example.proxy.demo1;

import com.example.proxy.demo1.impl.UserServerImpl;
import com.example.proxy.demo1.impl.UserServiceProxy;
import com.example.proxy.jdk_proxy.ProxyFactory;

public class TestProxy {

    /**
     * 静态代理
     * 优点: 可以在不修改目标类的前提下,扩展目标类的功能
     * 缺点:
     * 1.冗余,由于代理对象要实现和目标对象一致的接口,会产生很多的代理
     * 2.不易维护,一旦接口中增加方法,目标对象和代理对象都要进行修改
     *
     * @param args
     */
    public static void main(String[] args) {
        IUserService service = new UserServerImpl();
        System.out.println("service = " + service.getClass());
//        UserServiceProxy proxy = new UserServiceProxy(service);
//        proxy.saveUser();
        ProxyFactory factory = new ProxyFactory(service);
        IUserService proxyInstance = (IUserService) factory.getProxyInstance();
        System.out.println("proxyInstance = " + proxyInstance.getClass());
        proxyInstance.saveUser();


    }

}
